<?php

namespace App\Http\Controllers\Api\Comment;

use App\Http\Requests\Api\Comment\DcommentRequest;
use App\Http\Resources\DcommentResource;
use App\Models\Dcomment;
use App\Models\Dynamic;
use Illuminate\Support\Facades\Auth;

class DcommentController extends Controller
{

    public function index(DcommentRequest  $request)
    {
        $Dcomments = Dcomment::where('status',1)->where('dynamic_id',(int)$request->dynamic_id)->paginate(config('api.pagination.dcomment'));;
        return DcommentResource::collection($Dcomments);
    }
    public function store(DcommentRequest $request)
    {
        $user = Auth::guard('api')->user();

        Dcomment::create([
            'poster_id' => Dynamic::find($request->dynamic_id)->user->id,
            'content' => $request->input('content'),
            'dynamic_id' => $request->input('dynamic_id'),
            'replier_id' => $user->id,
            'replier_avatar' => $user->avatar,
            'replier_nickname' => $user->nickname,
            'receiver_id' =>$request->input('receiver_id'),
            'receiver_nickname' => $request->input('receiver_nickname'),
            'type' =>"dynamic",
        ]);

        return response()->json(['message' => '发布成功'], 201);
    }
    public function show(DcommentRequest $request)
    {
        return (new DcommentResource(Dcomment::find($request->id)));
    }
    public function update(DcommentRequest $request)
    {
        return (new DcommentResource(Dcomment::find($request->id)));
    }
    public function delete(DcommentRequest $request)
    {
        return (new DcommentResource(Dcomment::find($request->id)));
    }
}
